package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.WmsPm;
import com.qf.service.WmsPmService;
import com.qf.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * --- 愿许秋风知我意，赐我十亿人民币 ---
 *
 * @author HeErkang
 * @date 2024/7/22
 * @desc --- 万一赢了呢？ ---
 * @desc --- 今日课程 ---
 */
@RestController
@RequestMapping("/wms/pm/")
public class WmsPmController {

    @Autowired
    private WmsPmService service;

    /**
     * 查询全部计量单位
     * 分页和模糊搜索
     */

    @GetMapping("/list")
    public R findAll(@RequestParam HashMap<String,String> map) {
        System.out.println(map);
        int pageNum = Integer.parseInt(map.get("pageNum"));
        int pageSize = Integer.parseInt(map.get("pageSize"));
        PageHelper.startPage(pageNum,pageSize);

        List<WmsPm> list = service.findAll(map);
        PageInfo<WmsPm> info = new PageInfo<>(list);
        System.out.println(info);
        return R.ok(info);
    }

    // 删除
    @GetMapping("/del")
    public R delById(int pmId){
        System.out.println("接收到id = " + pmId);
        boolean isOk = service.deleteById(pmId);
        return R.ok(isOk);
    }

    // 修改
    @PostMapping("/update")
    public R updatePm(@RequestBody WmsPm pm){
        boolean isOk = service.updatePm(pm);
        return R.ok(isOk);
    }

    // 添加
    @PostMapping("/add")
    public R addPm(@RequestBody WmsPm pm){
        boolean isOk = service.addPm(pm);
        return R.ok(isOk);
    }
}
